package com.xcity.game.activity.newplayer.tracer;

import java.text.MessageFormat;

import com.xcity.game.activity.newplayer.NewPlayerDoingStr;
import com.xcity.game.activity.newplayer.NewPlayerTask;
import com.xcity.game.activity.newplayer.NewPlayerTracer;
import com.xcity.game.activity.newplayer.NewPlayerTracerLabel;

@NewPlayerTracerLabel(NewPlayerTracer.ARENA_RANK)
public class ArenaRankTracer implements NewPlayerTracer{

	@Override
	public boolean isDone(NewPlayerTask task) {
		if(task.getProgress()[0] > 0){
			if(task.getProgress()[0] <= task.getTemplate().getParam()[0]){
				return true;
			}
		}
		return false;
	}

	@Override
	public void onChange(NewPlayerTask task, Object... vals) {
		int rank = (int) vals[1] + 1;
		if(rank > PARAM0_MAX){
			rank = PARAM0_MAX;
		}
		if(rank <= 0){
			rank = 5000;
		}
		int[] progress = task.getProgress();
		if(progress[0] <= 0){
			progress[0] = rank;
		}else{
			if(progress[0] > rank){
				progress[0] = rank;
			}
		}
	}

	@Override
	public String getDoingStr(NewPlayerTask task) {
		return MessageFormat.format(NewPlayerDoingStr.STR_ARENA_RANK, task.getTemplate().getParam()[0]);
	}

}
